﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ART.Common;

namespace ART.Admini.Users
{
    public partial class UserLangDetail : System.Web.UI.Page
    {
        protected int Id = 0;
        protected int UId = 0;
        private ART.BLL.B_UserLang bll = new ART.BLL.B_UserLang();
        private ART.Model.M_UserLang model = new ART.Model.M_UserLang();
        private BLL.B_dictionary bll_dic = new BLL.B_dictionary();

        protected void Page_Load(object sender, EventArgs e)
        {
            Id = Common.LYRequest.GetInt("id", 0);
            UId = Common.LYRequest.GetInt("UId", 0);
#warning BLL.B_TBAdmin.IsPermissions(0x6c)

            if (!IsPostBack)
            {
                InitData();
            }
        }
        private void InitData()
        {
            JBind.BindList(dropLanguage, bll_dic.GetList("parentid=38").Tables[0], "DictionaryName", "id");
            dropLanguage.Items.Insert(0, new ListItem("请选择", "0"));
            JBind.BindList(dropLevelId, bll_dic.GetList("parentid=11").Tables[0], "DictionaryName", "id");
            dropLevelId.Items.Insert(0, new ListItem("请选择", "0"));

            if (Id > 0)
            {//edit
                model = bll.GetModel(Id);
                if (model != null)
                {
                    dropLanguage.SelectedValue = model.LangId.ToString();
                    dropLevelId.SelectedValue = model.LevelId.ToString();
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs p1)
        {
            if (Id > 0)
            {
                #region __________Edit__________
                model = bll.GetModel(Id);
                model.LangId = int.Parse(dropLanguage.SelectedValue);
                model.LevelId = int.Parse(dropLevelId.SelectedValue);
                if (bll.Update(model))
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Edit, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
            else
            {
                #region __________Add__________
                model.Uid = UId;
                model.LangId = int.Parse(dropLanguage.SelectedValue);
                model.LevelId = int.Parse(dropLevelId.SelectedValue);
                if (bll.Add(model) > 0)
                {
                    //B_operationLog.CreateOperationLog(B_operationLog.operationLogType.Add, "", "");
                    MessageBox.JSLoad(sender, "alert('保存成功!');reloadDlg(true);");
                }
                #endregion
            }
        }
    }
}
